import xlrd
from xlutils.copy import copy
import time
class OperExcel:

    def __init__(self,file_path=None,i=None):
        if file_path==None:
            self.file_path = '/Users/chengyanan/PycharmProjects/kuai8_appium/case/case.xls'
        else:
            self.file_path=file_path

        if i==None:
            i=0
        self.excel=self.get_excel()
        self.write_excel = copy(self.excel)
        self.data=self.get_sheets(i)

    def get_excel(self):
        '''
        获取excel
        '''
        excel=xlrd.open_workbook(self.file_path)
        return excel

    def get_sheets(self,i):
        '''
        获取sheet内容
        '''
        tables=self.excel.sheets()[i]
        return tables

    def get_lines(self):
        '''
        获取行数
        '''
        lines=self.data.nrows
        return lines

    def get_cell(self,row,cell):
        data=self.data.cell(row,cell).value
        return data

    def write_result_value(self,row=None,value=None):
        sheet = self.write_excel.get_sheet(0)
        sheet.write(row, 8, value)


    def save_kuai8_result(self):
        times = time.strftime('%Y.%m.%d-%H:%M', time.localtime(time.time()))
        self.write_excel.save('../report/kuai8_app'+times+'.xls')


    def get_actual_result(self,cell):
        '''
        获取实际结果
        '''
        result=self.data.col_values(cell)
        return result

if __name__ == '__main__':
    opre=OperExcel()
    print(opre.get_lines())
    opre.write_result_value(row=5,value='pass')
    opre.write_result_value(row=7,value='pass')

    opre.save_kuai8_result()
